/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Autenticarse.java
 *
 * Created on 10/04/2009, 02:16:16 PM
 */

package interfaz;

import Funcionalidad.Controlador;
import Funcionalidad.ControlAutenticar;
import java.lang.String;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import Conecciondb.ConexionDb;
import Funcionalidad.Encriptador;
/**
 *
 * @author legyoroz
 */
public class Autenticarse extends javax.swing.JFrame {
private boolean retorno;

    /** Creates new form Autenticarse */
    public Autenticarse() {
        initComponents();
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jComboBox2 = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        tesfieldUsuario = new javax.swing.JTextField();
        passUsuario = new javax.swing.JPasswordField();
        botonEnviarDatos = new javax.swing.JButton();
        botonCancelarenvio = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setForeground(new java.awt.Color(51, 51, 255));
        jLabel1.setText("Autenticacion ");

        jLabel2.setText("Usuario(# documento de indentidad)");

        jLabel3.setText("Contraseña");

        tesfieldUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tesfieldUsuarioActionPerformed(evt);
            }
        });

        passUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                passUsuarioActionPerformed(evt);
            }
        });

        botonEnviarDatos.setText("Enviar");
        botonEnviarDatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEnviarDatosActionPerformed(evt);
            }
        });

        botonCancelarenvio.setText("Cancelar");
        botonCancelarenvio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarenvioActionPerformed(evt);
            }
        });

        jComboBox1.setMaximumRowCount(2);
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "administrador", "estudiante" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CC", "TI" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(botonEnviarDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botonCancelarenvio))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(passUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                            .addComponent(tesfieldUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tesfieldUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(passUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCancelarenvio)
                    .addComponent(botonEnviarDatos))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tesfieldUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tesfieldUsuarioActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tesfieldUsuarioActionPerformed

    private void passUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passUsuarioActionPerformed
        // TODO add your handling code here:
       // JOptionPane.showMessageDialog(null, contraseña);
}//GEN-LAST:event_passUsuarioActionPerformed

    private void botonCancelarenvioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarenvioActionPerformed
        // TODO add your handling code here:
        System.exit(0);
}//GEN-LAST:event_botonCancelarenvioActionPerformed

    private void botonEnviarDatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEnviarDatosActionPerformed
        // TODO add your handling code here:
        //if(estadoRadAdm) JOptionPane.showMessageDialog(null,"esta seleccionando rad estudiante");
        Controlador contr= new Controlador();
        ControlAutenticar aux = new ControlAutenticar();
        String tipo;
        if(jComboBox3.getSelectedItem().equals("CC")) tipo="CC";
        else tipo="TI";
        if(jComboBox1.getSelectedItem().equals("estudiante")){
          JOptionPane.showMessageDialog(null,"selecciono estudiante "+getTesfieldUsuario());
          
          if(aux.VerificarEstudiante(getTesfieldUsuario(),
                   Encriptador.getEncoded(getPassUsuario(), "MD5"),tipo)){
              aux.setUsuarioEjecutando(getTesfieldUsuario());
              //identificador=getTesfieldUsuario();
            this.dispose();
            JOptionPane.showMessageDialog(null,"bienvenido alumno");
            new OpcionesEst().setVisible(true);
          }
          else 
JOptionPane.showMessageDialog(null,"datos incorrectos\n Usuario:"+getTesfieldUsuario()+"\n Contraseña:"+ getPassUsuario());
        }
        else{
          JOptionPane.showMessageDialog(null,"ha seleccionado admin");
          if(aux.VerificarAdministrador(getTesfieldUsuario(),getPassUsuario(),tipo)){
              aux.setUsuarioEjecutando(getTesfieldUsuario());
              this.dispose();
              JOptionPane.showMessageDialog(null,"bienvenido administrador");
              new Opcionesadmin().setVisible(true);
          }else 
JOptionPane.showMessageDialog(null,"datos incorrectos\n Usuario:"+getTesfieldUsuario()+"\n Contraseña:"+ getPassUsuario());
        }
    }//GEN-LAST:event_botonEnviarDatosActionPerformed

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// TODO add your handling code here:

}//GEN-LAST:event_jComboBox1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Autenticarse().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCancelarenvio;
    private javax.swing.JButton botonEnviarDatos;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField passUsuario;
    private javax.swing.JTextField tesfieldUsuario;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the passUsuario
     */
    public String  getPassUsuario() {
        return passUsuario.getText();
    }

    /**
     * @return the radAdmin
     */
  /*  public boolean getRadAdmin() {
        
    }*/

    /**
     * @return the radEstudiante
     */
 /*   public boolean getRadEstudiante() {
        
    }*/

    /**
     * @return the tesfieldUsuario
     */
    public String getTesfieldUsuario() {
        return tesfieldUsuario.getText();
    }

    /**
     * @param radAdmin the radAdmin to set
     */
    public void setRadAdmin(boolean estadoRadAdm) {
        estadoRadAdm=true;
    }

    /**
     * @param radEstudiante the radEstudiante to set
     */
    public void setRadEstudiante(boolean estadoRadEst) {
        estadoRadEst=true;
    }
   
}
